package org.leetcode.easy.leetcode13;

import java.sql.SQLOutput;
import java.util.HashMap;

public class Solution
{
    public static int romanToInt(String s)
    {
        String[] romanString = s.split("");
        int num =0;
        HashMap<String, Integer> romanChar = new HashMap<>();
        romanChar.put("I",1);
        romanChar.put("V",5);
        romanChar.put("X",10);
        romanChar.put("L",50);
        romanChar.put("C",100);
        romanChar.put("D",500);
        romanChar.put("M",1000);

        HashMap<String, Integer> romanChar2 = new HashMap<>();
        romanChar2.put("IV",4);
        romanChar2.put("IX",9);
        romanChar2.put("XL",40);
        romanChar2.put("XC",90);
        romanChar2.put("CD",400);
        romanChar2.put("CM",900);


        for (int i = 0; i < romanString.length; i++) {
            if (i<romanString.length-1 && romanChar2.get(romanString[i]+romanString[i+1])!=null)
            {

                num += romanChar2.get(romanString[i] + romanString[i + 1]);
                i+=1;
            }else
            {
                num += romanChar.get(romanString[i]);

            }
        }
        return num;
    }


    public static void main(String[] args) {
        int xii = romanToInt("MCMXCIV");
        System.out.println(xii);
    }

}
